

import datetime
import os

from lj_tool import tool_log, tool_run
# from lj_action import action_data
from lj_tool import lj_bean_conn, tool_arr, tool_run, tool_ssh
# from lj_tool import tool_minio
# from lj_action import action_ai

# server = action_ai.list_ai_server()

# t_ssh = tool_ssh.init(lj_bean_conn.init_ai_server(server))

# for i in range(0, 10000):
#     t_ssh.put_conn(t_ssh.get_conn())
#     t_ssh.put_conn(t_ssh.get_conn())
#     t_ssh.put_conn(t_ssh.get_conn())
#     t_ssh.put_conn(t_ssh.get_conn())
#     t_ssh.put_conn(t_ssh.get_conn())
#     print(i)
# tool_ssh.init(lj_bean_conn.init_ai_server(server))
# tool_ssh.init(lj_bean_conn.init_ai_server(server))
# tool_ssh.init(lj_bean_conn.init_ai_server(server))
# tool_ssh.init(lj_bean_conn.init_ai_server(server))
# tool_ssh.init(lj_bean_conn.init_ai_server(server))
# tool_ssh.init(lj_bean_conn.init_ai_server(server))


def job():
    print(datetime.datetime.now())


tool_run.do_everyday(job, "13:46")
tool_run.start()

# print(datetime.datetime.now().strftime("%Y%m%d"))
# today = datetime.datetime.now().strftime("%Y%m%d")

# tool_ssh.send_file(lj_bean_conn.BeanConn("61.52.247.249", "file_server", "-x}{d#-l=tMR", 12000),
#                    "temp/14401971319-6d97475c2fce4457a453f459e0c966d5-20230720110346-Algae-image.jpg",
#                    f"/com/nginx/www/file/{today}/2.jpg")
# os.remove(
#     "tmp/14401971319-6d97475c2fce4457a453f459e0c966d5-20230720110346-Algae-image.jpg")


def days(str1, str2):
    try:
        date1 = datetime.datetime.strptime(str1[0:8], "%Y%m%d")
        date2 = datetime.datetime.strptime(str2[0:8], "%Y%m%d")
        num = (date1-date2).days
    except:
        # 时间异常的直接删除
        num = 4
    return num


# 清理本地文件
# base_dir = "temp/"
# local_files = [os.path.join(file) for file in os.listdir(base_dir)]
# for local_file in local_files:
#     file_name_list = local_file.split("-")
#     if len(file_name_list) == 1:
#         if days(datetime.datetime.now().strftime("%Y%m%d%H%M%S"), file_name_list[0]) > 3:
#             tool_log.info(f"删除本地文件-{base_dir}{local_file}")
#             os.remove(f"{base_dir}{local_file}")
#     elif len(file_name_list) > 3:
#         print("sd")
